home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / OOPTUT34.ZIP / COMPAT.TXT < prev    next >
Text File  |  1993-06-12  |  2KB  |  46 lines

  1.                   OBJECT TYPE COMPATIBILITY.
  2.                   ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  3.  
  4.  Turbo Pascal's strict type compatibility rules are relaxed to some extent
  5.  as a result of inheritance. In addition to everything else, a descendant
  6.  type inherits type compatibility with all its ancestor types.
  7.  
  8.  This extended type compatibility takes three forms:
  9.      between object instances
  10.      between pointers to object instances
  11.      between formal and actual parameters.
  12.  
  13.  Descendant types can be freely used in place of ancestor types, but not
  14.  vice versa. Thus if a point is a descendant of a location and a circle
  15.  is a descendant of a point, then the following assignments are legal:
  16.  
  17.      ALocation := APoint;
  18.      APoint    := ACircle;
  19.      ALocation := ACircle;     but the reverse is not legal.
  20.  
  21.  Descendant types contain everything that their ancestor types contain by
  22.  virtue of inheritance. Therefore a descendant type is either exactly the
  23.  same size or usually larger than its ancestors, but never smaller.
  24.  Assigning an ancestor object to a descendant object could leave some of
  25.  the descendant's fields undefined after the assignment, which is dangerous
  26.  and therefore illegal.
  27.  
  28.  In the assignment statement, only the fields that the two types have in
  29.  common are copied from the source to the destination, so the assignment
  30.       ALocation := ACircle;
  31.  only copies the X and Y fields which the two have in common.
  32.  
  33.  Similarly pointers to descendant can be assigned to pointers to ancestors.
  34.  
  35.      PLocation := PPoint;
  36.      PPoint    := PCircle;
  37.      PLocation := PCircle;     but not vice versa.
  38.  
  39.  A formal parameter of a given object type can take as an actual parameter
  40.  an object of its own or any descendant type. Thus if a procedure requires
  41.  a parameter of type point, the actual parameter could be of type point or
  42.  type circle but not location.
  43.  
  44. COMPAT.TXT
  45. 1.6.93
  46.